// 这是一个背包问题, 背包的容量为块, 需要求最大物品的价值
//3
//737270
//737272
//737288
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let m;
let initArr = [];
rl.on("line", (line)=>{
    if(m === undefined) {
         m = Number(line.trim())
    } else {
        let num = Number(line.trim())
        initArr.push(num)
        if(initArr.length === m) {
            console.log(getResult(m, initArr))

            // clear
            m = undefined
            initArr.length = 0
        }
    }
})

function getResult(m, initArr) {
    let n = 1474560/512
    let sizeArr = initArr.map((val, index) => Math.ceil(val/512))
    let dp = new Array(m + 1).fill(null).map(_ => new Array(n + 1).fill(0))
    for (let i = 1; i <= m  ; i++) {
        for (let j = 1; j <= n ; j++) {
            let weigth = sizeArr[i - 1]
            if(j >= weigth) {
                dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - weigth] + initArr[i - 1])
            } else {
                dp[i][j] = dp[i - 1][j]
            }
        }
    }
    return dp[m][n]
}